home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / e_mac / e_gettimeofday.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-18  |  607 b   |  29 lines  |  [TEXT/CWIE]

  1. /* e_gettimeofday.c */
  2. /* 18Oct95  e   -- from runtime.c */
  3.  
  4. #include <utime.h>
  5.  
  6. #define TICKS_PER_SEC 60
  7.  
  8. static unsigned long then, ttks;
  9.  
  10. void gettimeofday ( struct timeval *t, int huh )
  11. {
  12.     unsigned long now, ticks;
  13.  
  14.     now = LMGetTime();
  15.     ticks = LMGetTicks();
  16.     ticks = ((ticks % TICKS_PER_SEC) * 1000000) / TICKS_PER_SEC;
  17.     if( now == then && ticks <= ttks )
  18.     { // no or "negative" time has passed
  19.       // make it look like some time has passed, if we can, within the same second
  20.       ticks = ttks + (( ttks < 999999 ) ? 1 : 0);
  21.     }
  22.     then = now;
  23.     t->tv_sec = now;
  24.     ttks = ticks;
  25.     t->tv_usec = ticks;
  26. }
  27.  
  28. // end
  29.